#!/usr/bin/env python
# encoding=utf-8

"""
将旧的数据转移到新的库中
"""

import sys

from pymongo import MongoClient
from scpy.logger import get_logger

reload(sys)
sys.setdefaultencoding('utf-8')
logger = get_logger(__file__)
MONGO = MongoClient('10.132.23.104', 27017)


def trans():
    coll_fr = MONGO['crawler_company_all']['stockAnnouncementnew']  # from
    coll_to = MONGO['stockProj']['shenhuStockAnno']  # to

    succ = 0
    for index, item in enumerate(coll_fr.find()):
        logger.info('index %s, succ %s' % (index, succ))

        if 'content' not in item:
            continue

        data = coll_to.find_one({'_id': item['_id']})
        if not data:
            continue

        coll_to.update_one({'_id': item['_id']}, {'$set': {'fileKey': item['file'], 'content': item['content']}})
        succ += 1

if __name__ == '__main__':
    trans()